/*
 * PublicDefine.h
 *
 *  Created on: 2017年5月26日
 *      Author: orange
 */

#ifndef PUBLICDEFINE_H_
#define PUBLICDEFINE_H_

#include <pthread.h>
#include <uuid/uuid.h>
#include <string>

#include "cuckoohash_map.hh"

class Plugin;

class JuzEvent;

typedef std::string juzString;

#define ARRSIZE(x)   sizeof(x) / sizeof(x[0])

struct JUZ_SOCKET_DATA
{
	int nLen;//数据总长度
	char what;
	char type;
	char arg1;
	char arg2;
	char sum;
};

#define SOCKETHEAD  sizeof(JUZ_SOCKET_DATA)


struct JUZ_EPOLL_CLIEN
{
	bool mIsencrypt;//是否已经加密
	char mKey[32];//密钥
	int  mPort;  //端口
	char mIp[32]; //ip地址

	int  mCount;//已经接了多少个数据
	void *mpData = NULL; //数据
	JUZ_SOCKET_DATA mJSD;  //协议头

	pthread_mutex_t *mMutex;
	uuid_t uu;//唯一识别

	JUZ_EPOLL_CLIEN();
	~JUZ_EPOLL_CLIEN();
};

struct JUZ_TBB_DATA
{
	JUZ_EPOLL_CLIEN *mTo = NULL;
};
struct Juz_Socket_Validation
{
	char what;
	char type;
	char arg1;
	char arg2;
	Juz_Socket_Validation(char what = 0x00,char type = 0x00,char arg1 = 0x00,char arg2 = 0x00);
	bool isCmp(char what = 0x00,char type = 0x00,char arg1 = 0x00,char arg2 = 0x00);
};

typedef cuckoohash_map<int, JUZ_TBB_DATA>   HashMapSocket;
typedef cuckoohash_map<int, int*>  HashMapTcpCheck;


//登录用户长度 字节
#define LOGINUSERSIZE   32

struct JuzLoginInfo
{
	char user[LOGINUSERSIZE];
	char pass[LOGINUSERSIZE];
};

struct JuzLoginInfoAndroid
{
	char serverUser[LOGINUSERSIZE];
	char user[LOGINUSERSIZE];
	char pass[LOGINUSERSIZE];
};
struct STRUCT_AskUser
{
	JuzLoginInfoAndroid ju;
	int nfd;
	bool isYes;
};

struct JUZ_ANDROID_CLIENT
{
	JuzLoginInfoAndroid loginInfo;
	bool isLogin = false;//是否已经登录
};

struct JuzCHATANDROID
{
	char serverUser[LOGINUSERSIZE];
	char user[LOGINUSERSIZE];
	char chat[127];//聊天内容
	char place[LOGINUSERSIZE];
};

struct JUZCHATINFO
{
	char user[LOGINUSERSIZE];
	char chat[127];//聊天内容
	char place[LOGINUSERSIZE];
};
struct JUZVERSION
{
	char type;
	int version;
	char data[64];
};
struct JUZSENDINFO
{
	uuid_t uu;
	JuzEvent *event;
};

class JuzLog
{
private:
	static Plugin *sendPl;
public:
	static void Init(Plugin*);
	static void LogStr(const char *msg,int nGra = 3);
	static void LogA(int nGra,const char *src,...);
};
#endif /* PUBLICDEFINE_H_ */
